domlist = xc.domain_getinfo()
doms = {}
for d in domlist:
- domid = str(d['dom'])
+ domid = d['dom']
doms[domid] = d
return doms
"""Get info about a single domain from xc.
Returns None if not found.
- @param dom domain id
+ @param dom domain id (int)
"""
- try:
- dom = int(dom)
- except ValueError:
- return None
dominfo = xc.domain_getinfo(dom, 1)
if dominfo == [] or dominfo[0]['dom'] != dom:
dominfo = None
"""
doms = self.xen_domains()
for config in self.db.fetchall("").values():
- domid = str(sxp.child_value(config, 'id'))
+ domid = int(sxp.child_value(config, 'id'))
if domid in doms:
try:
self._new_domain(config, doms[domid])
- self.update_domain(domid)
except Exception, ex:
- log.exception("Error recreating domain info: id=%s", domid)
+ log.exception("Error recreating domain info: id=%d", domid)
self._delete_domain(domid)
else:
self._delete_domain(domid)
info domain info
"""
- self.db.save(info.id, info.sxpr())
+ self.db.save(str(info.id), info.sxpr())
def close(self):
pass
"""
dominfo = XendDomainInfo.recreate(savedinfo, info)
self.domains[dominfo.id] = dominfo
+ self.sync_domain(dominfo)
return dominfo
def _add_domain(self, info, notify=True):
for i, d in self.domains.items():
if i != d.id:
del self.domains[i]
- self.db.delete(i)
+ self.db.delete(str(i))
if info.id in self.domains:
notify = False
self.domains[info.id] = info
del self.domains[id]
if notify:
eserver.inject('xend.domain.died', [info.name, info.id])
- self.db.delete(id)
+ self.db.delete(str(id))
def reap(self):
"""Look for domains that have crashed or stopped.
not(d['running'] or d['paused'] or d['blocked']))
if dead:
casualties.append(d)
- destroyed = 0
for d in casualties:
- id = str(d['dom'])
+ id = d['dom']
#print 'reap>', id
dominfo = self.domains.get(id)
name = (dominfo and dominfo.name) or '??'
if dominfo and dominfo.is_terminated():
#print 'reap> already terminated:', id
continue
- log.debug('XendDomain>reap> domain died name=%s id=%s', name, id)
+ log.debug('XendDomain>reap> domain died name=%s id=%d', name, id)
if d['shutdown']:
reason = shutdown_reason(d['shutdown_reason'])
- log.debug('XendDomain>reap> shutdown name=%s id=%s reason=%s', name, id, reason)
+ log.debug('XendDomain>reap> shutdown name=%s id=%d reason=%s', name, id, reason)
if reason in ['suspend']:
if dominfo and dominfo.is_terminated():
- log.debug('XendDomain>reap> Suspended domain died id=%s', id)
+ log.debug('XendDomain>reap> Suspended domain died id=%d', id)
else:
eserver.inject('xend.domain.suspended', [name, id])
if dominfo:
self.domain_restart_schedule(id, reason)
else:
if xroot.get_enable_dump():
- self.domain_dumpcore(int(id))
+ self.domain_dumpcore(id)
eserver.inject('xend.domain.exit', [name, id, 'crash'])
- destroyed += 1
self.final_domain_destroy(id)
def refresh(self, cleanup=False):
scheduler.now(self.domain_restarts)
def update_domain(self, id):
- """Update the saved info for a domain.
-
- @param id: domain id
- """
- dominfo = self.domains.get(id)
- if dominfo:
- self.sync_domain(dominfo)
-
- def refresh_domain(self, id):
- """Refresh information for a single domain.
+ """Update information for a single domain.
@param id: domain id
"""
@param id: domain id
@return: domain object (or None)
"""
- id = str(id)
- self.refresh_domain(id)
+ self.update_domain(id)
return self.domains.get(id)
def domain_lookup(self, id):
- name = str(id)
- dominfo = self.domains.get_by_name(name) or self.domains.get(id)
+ dominfo = self.domains.get(id)
if not dominfo:
try:
info = self.xen_domain(id)
if info:
- log.info("Creating entry for unknown domain: id=%s", name)
+ log.info("Creating entry for unknown domain: id=%d", id)
dominfo = XendDomainInfo.recreate(None, info, unknown=True)
self._add_domain(dominfo)
except Exception, ex:
- log.exception("Error creating domain info: id=%s", name)
+ log.exception("Error creating domain info: id=%d", id)
+ return dominfo
+
+ def domain_lookup_by_name(self, name):
+ dominfo = self.domains.get_by_name(name)
+ if not dominfo:
+ try:
+ id = int(name)
+ dominfo = self.domain_lookup(id)
+ except ValueError:
+ pass
return dominfo
def domain_unpause(self, id):
dominfo = self.domain_lookup(id)
eserver.inject('xend.domain.unpause', [dominfo.name, dominfo.id])
try:
- return xc.domain_unpause(dom=dominfo.dom)
+ return xc.domain_unpause(dom=dominfo.id)
except Exception, ex:
raise XendError(str(ex))
dominfo = self.domain_lookup(id)
eserver.inject('xend.domain.pause', [dominfo.name, dominfo.id])
try:
- return xc.domain_pause(dom=dominfo.dom)
+ return xc.domain_pause(dom=dominfo.id)
except Exception, ex:
raise XendError(str(ex))
@param id: domain id
@param reason: shutdown reason
"""
- log.debug('domain_restart_schedule> %s %s %d', id, reason, force)
+ log.debug('domain_restart_schedule> %d %s %d', id, reason, force)
dominfo = self.domain_lookup(id)
if not dominfo:
return
except:
#todo
try:
- val = xc.domain_destroy(dom=int(id))
+ val = xc.domain_destroy(dom=id)
except Exception, ex:
raise XendError(str(ex))
return val
"""
dominfo = self.domain_lookup(id)
try:
- return xc.domain_pincpu(int(dominfo.id), vcpu, cpumap)
+ return xc.domain_pincpu(dominfo.id, vcpu, cpumap)
except Exception, ex:
raise XendError(str(ex))
"""
dominfo = self.domain_lookup(id)
try:
- return xc.bvtsched_domain_set(dom=dominfo.dom, mcuadv=mcuadv,
+ return xc.bvtsched_domain_set(dom=dominfo.id, mcuadv=mcuadv,
warpback=warpback, warpvalue=warpvalue,
warpl=warpl, warpu=warpu)
except Exception, ex:
"""
dominfo = self.domain_lookup(id)
try:
- return xc.bvtsched_domain_get(dominfo.dom)
+ return xc.bvtsched_domain_get(dominfo.id)
except Exception, ex:
raise XendError(str(ex))
def domain_cpu_sedf_set(self, id, period, slice, latency, extratime, weight):
"""Set Simple EDF scheduler parameters for a domain.
"""
- dominfo = self.domain_lookup(id)
+ dominfo = self.domain_lookup(id)
try:
- return xc.sedf_domain_set(dominfo.dom, period, slice, latency, extratime, weight)
+ return xc.sedf_domain_set(dominfo.id, period, slice, latency, extratime, weight)
except Exception, ex:
raise XendError(str(ex))
def domain_cpu_sedf_get(self, id):
- """Get Atropos scheduler parameters for a domain.
+ """Get Simple EDF scheduler parameters for a domain.
"""
dominfo = self.domain_lookup(id)
try:
- return xc.sedf_domain_get(dominfo.dom)
+ return xc.sedf_domain_get(dominfo.id)
except Exception, ex:
raise XendError(str(ex))
"""
dominfo = self.domain_lookup(id)
val = dominfo.device_create(devconfig)
- self.update_domain(dominfo.id)
+ self.sync_domain(dominfo)
return val
- def domain_device_configure(self, id, devconfig, idx):
+ def domain_device_configure(self, id, devconfig, devid):
"""Configure an existing device for a domain.
@param id: domain id
@param devconfig: device configuration
- @param idx: device index
+ @param devid: device index
@return: updated device configuration
"""
dominfo = self.domain_lookup(id)
- val = dominfo.device_configure(devconfig, idx)
- self.update_domain(dominfo.id)
+ val = dominfo.device_configure(devconfig, devid)
+ self.sync_domain(dominfo)
return val
- def domain_device_refresh(self, id, type, idx):
+ def domain_device_refresh(self, id, type, devid):
"""Refresh a device.
@param id: domain id
- @param idx: device index
+ @param devid: device index
@param type: device type
"""
dominfo = self.domain_lookup(id)
- val = dominfo.device_refresh(type, idx)
- self.update_domain(dominfo.id)
+ val = dominfo.device_refresh(type, devid)
+ self.sync_domain(dominfo)
return val
- def domain_device_destroy(self, id, type, idx):
+ def domain_device_destroy(self, id, type, devid):
"""Destroy a device.
@param id: domain id
- @param idx: device index
+ @param devid: device index
@param type: device type
"""
dominfo = self.domain_lookup(id)
- val = dominfo.device_destroy(type, idx)
- self.update_domain(dominfo.id)
+ val = dominfo.device_destroy(type, devid)
+ self.sync_domain(dominfo)
return val
def domain_devtype_ls(self, id, type):
dominfo = self.domain_lookup(id)
return dominfo.getDeviceSxprs(type)
- def domain_devtype_get(self, id, type, idx):
+ def domain_devtype_get(self, id, type, devid):
"""Get a device from a domain.
@param id: domain
@param type: device type
- @param idx: device index
+ @param devid: device index
@return: device object (or None)
"""
dominfo = self.domain_lookup(id)
- return dominfo.getDeviceByIndex(type, idx)
+ return dominfo.getDeviceByIndex(type, devid)
def domain_vif_limit_set(self, id, vif, credit, period):
"""Limit the vif's transmission rate
"""
dominfo = self.domain_lookup(id)
try:
- return xc.shadow_control(dominfo.dom, op)
+ return xc.shadow_control(dominfo.id, op)
except Exception, ex:
raise XendError(str(ex))
def domain_maxmem_set(self, id, mem):
"""Set the memory limit for a domain.
- @param dom: domain
+ @param id: domain
@param mem: memory limit (in MB)
@return: 0 on success, -1 on error
"""
dominfo = self.domain_lookup(id)
maxmem = int(mem) * 1024
try:
- return xc.domain_setmaxmem(dominfo.dom, maxmem_kb = maxmem)
+ return xc.domain_setmaxmem(dominfo.id, maxmem_kb = maxmem)
except Exception, ex:
raise XendError(str(ex))
- def domain_mem_target_set(self, id, target):
+ def domain_mem_target_set(self, id, mem):
"""Set the memory target for a domain.
@param id: domain
- @param target: memory target (in MB)
+ @param mem: memory target (in MB)
@return: 0 on success, -1 on error
"""
dominfo = self.domain_lookup(id)
- return dominfo.mem_target_set(target)
+ return dominfo.mem_target_set(mem)
def domain_dumpcore(self, id):
"""Save a core dump for a crashed domain.
def domain_exists(name):
# See comment in XendDomain constructor.
xd = get_component('xen.xend.XendDomain')
- return xd.domain_lookup(name)
+ return xd.domain_lookup_by_name(name)
def shutdown_reason(code):
"""Get a shutdown reason from a code.
self.config = None
self.id = None
- self.dom = None
self.cpu_weight = 1
self.start_time = None
self.name = None
@param dom: domain id
"""
- self.dom = int(dom)
- self.id = str(dom)
+ self.id = int(dom)
def getDomain(self):
- return self.dom
+ return self.id
def getName(self):
return self.name
return
if dominfo.is_terminated():
return
- if not self.dom or (dominfo.dom != self.dom):
+ if not self.id or (dominfo.id != self.id):
raise VmError('vm name clash: ' + name)
def construct(self, config):
if self.memory is None:
raise VmError('missing memory size')
cpu = sxp.child_value(config, 'cpu')
- if self.recreate and self.dom and cpu is not None and int(cpu) >= 0:
- xc.domain_pincpu(self.dom, 0, 1<<int(cpu))
+ if self.recreate and self.id and cpu is not None and int(cpu) >= 0:
+ xc.domain_pincpu(self.id, 0, 1<<int(cpu))
try:
image = sxp.child_value(self.config, 'image')
vcpus = sxp.child_value(image, 'vcpus')
if self.channel:
self.channel.close()
self.channel = None
- if self.dom is None: return 0
+ if self.id is None: return 0
try:
- return xc.domain_destroy(dom=self.dom)
+ return xc.domain_destroy(dom=self.id)
except Exception, err:
log.exception("Domain destroy failed: %s", self.name)
def show(self):
"""Print virtual machine info.
"""
- print "[VM dom=%d name=%s memory=%d" % (self.dom, self.name, self.memory)
+ print "[VM dom=%d name=%s memory=%d" % (self.id, self.name, self.memory)
print "image:"
sxp.show(self.image)
print
self.start_time = time.time()
if self.restore:
return
- dom = self.dom or 0
+ dom = self.id or 0
memory = self.memory
try:
cpu = int(sxp.child_value(self.config, 'cpu', '-1'))
if ramdisk and not os.path.isfile(ramdisk):
raise VmError('Kernel ramdisk does not exist: %s' % ramdisk)
if len(cmdline) >= 256:
- log.warning('kernel cmdline too long, domain %d', self.dom)
- dom = self.dom
+ log.warning('kernel cmdline too long, domain %d', self.id)
+ dom = self.id
buildfn = getattr(xc, '%s_build' % ostype)
flags = 0
if self.netif_backend: flags |= SIF_NET_BE_DOMAIN
if info:
local = int(sxp.child_value(info, "local_port", 0))
remote = int(sxp.child_value(info, "remote_port", 1))
- self.channel = channelFactory().openChannel(self.dom,
+ self.channel = channelFactory().openChannel(str(self.id),
local_port=local,
remote_port=remote)
#todo: self.memory?
memory = sxp.child_value(self.config, "memory")
# Create an event channel
- device_channel = channel.eventChannel(0, self.dom)
+ device_channel = channel.eventChannel(0, self.id)
# see if a vncviewer was specified
# XXX RN: bit of a hack. should unify this, maybe stick in config space
vncconnect=""
os.system(device_model
+ " -f %s" % device_config
+ vncconnect
- + " -d %d" % self.dom
+ + " -d %d" % self.id
+ " -p %d" % device_channel['port1']
+ " -m %s" % memory)
maxmem = int(maxmem)
except:
raise VmError("invalid maxmem: " + str(maxmem))
- xc.domain_setmaxmem(vm.dom, maxmem_kb = maxmem * 1024)
+ xc.domain_setmaxmem(vm.id, maxmem_kb = maxmem * 1024)
#============================================================================
# Register image handlers.
fn = FormFn(self.xd.domain_configure,
[['dom', 'int'],
['config', 'sxpr']])
- return fn(req.args, {'dom': self.dom.dom})
+ return fn(req.args, {'dom': self.dom.id})
def op_unpause(self, op, req):
- val = self.xd.domain_unpause(self.dom.name)
+ val = self.xd.domain_unpause(self.dom.id)
return val
def op_pause(self, op, req):
- val = self.xd.domain_pause(self.dom.name)
+ val = self.xd.domain_pause(self.dom.id)
return val
def op_shutdown(self, op, req):
fn = FormFn(self.xd.domain_shutdown,
- [['dom', 'str'],
+ [['dom', 'int'],
['reason', 'str'],
['key', 'int']])
val = fn(req.args, {'dom': self.dom.id})
def op_destroy(self, op, req):
fn = FormFn(self.xd.domain_destroy,
- [['dom', 'str'],
+ [['dom', 'int'],
['reason', 'str']])
val = fn(req.args, {'dom': self.dom.id})
req.setHeader("Location", "%s/.." % req.prePathURL())
def do_save(self, op, req):
fn = FormFn(self.xd.domain_save,
- [['dom', 'str'],
+ [['dom', 'int'],
['file', 'str']])
val = fn(req.args, {'dom': self.dom.id})
return 0
def do_migrate(self, op, req):
fn = FormFn(self.xd.domain_migrate,
- [['dom', 'str'],
+ [['dom', 'int'],
['destination', 'str'],
['live', 'int'],
['resource', 'int']])
def op_pincpu(self, op, req):
fn = FormFn(self.xd.domain_pincpu,
- [['dom', 'str'],
+ [['dom', 'int'],
['vcpu', 'int'],
['cpumap', 'int']])
val = fn(req.args, {'dom': self.dom.id})
def op_cpu_bvt_set(self, op, req):
fn = FormFn(self.xd.domain_cpu_bvt_set,
- [['dom', 'str'],
+ [['dom', 'int'],
['mcuadv', 'int'],
['warpback', 'int'],
['warpvalue', 'int'],
def op_cpu_sedf_set(self, op, req):
fn = FormFn(self.xd.domain_cpu_sedf_set,
- [['dom', 'str'],
+ [['dom', 'int'],
['period', 'int'],
['slice', 'int'],
['latency', 'int'],
def op_maxmem_set(self, op, req):
fn = FormFn(self.xd.domain_maxmem_set,
- [['dom', 'str'],
+ [['dom', 'int'],
['memory', 'int']])
val = fn(req.args, {'dom': self.dom.id})
return val
def op_mem_target_set(self, op, req):
fn = FormFn(self.xd.domain_mem_target_set,
- [['dom', 'str'],
+ [['dom', 'int'],
['target', 'int']])
val = fn(req.args, {'dom': self.dom.id})
return val
def op_devices(self, op, req):
fn = FormFn(self.xd.domain_devtype_ls,
- [['dom', 'str'],
+ [['dom', 'int'],
['type', 'str']])
val = fn(req.args, {'dom': self.dom.id})
return val
def op_device(self, op, req):
fn = FormFn(self.xd.domain_devtype_get,
- [['dom', 'str'],
+ [['dom', 'int'],
['type', 'str'],
['idx', 'int']])
val = fn(req.args, {'dom': self.dom.id})
def op_device_create(self, op, req):
fn = FormFn(self.xd.domain_device_create,
- [['dom', 'str'],
+ [['dom', 'int'],
['config', 'sxpr']])
val = fn(req.args, {'dom': self.dom.id})
return val
def op_device_refresh(self, op, req):
fn = FormFn(self.xd.domain_device_refresh,
- [['dom', 'str'],
+ [['dom', 'int'],
['type', 'str'],
['idx', 'str']])
val = fn(req.args, {'dom': self.dom.id})
def op_device_destroy(self, op, req):
fn = FormFn(self.xd.domain_device_destroy,
- [['dom', 'str'],
+ [['dom', 'int'],
['type', 'str'],
['idx', 'str']])
val = fn(req.args, {'dom': self.dom.id})
def op_device_configure(self, op, req):
fn = FormFn(self.xd.domain_device_configure,
- [['dom', 'str'],
+ [['dom', 'int'],
['config', 'sxpr'],
['idx', 'str']])
val = fn(req.args, {'dom': self.dom.id})
def op_vif_limit_set(self, op, req):
fn = FormFn(self.xd.domain_vif_limit_set,
- [['dom', 'str'],
+ [['dom', 'int'],
['vif', 'int'],
['credit', 'int'],
['period', 'int']])